<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<c:url value='/insdep/easyui_full.css'/>" rel="stylesheet"
	type="text/css">
<link href="<c:url value='/insdep/icon.css'/>" rel="stylesheet" type="text/css">
<script type="text/javascript"
	src="<c:url value='/insdep/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/insdep/jquery.easyui-1.5.2.min.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/insdep/insdep-extend.min.js'/>"></script>
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		/* 打开更新信息窗口 */
		function updateinfo(){
			$("#updatewithemail").window('open');
		}
		
		/* 新邮件选取主收件人 */
		function choosegenmen(){
			$("#newemailgenlist").datagrid({url: 'newemailemps'});
			$("#newemailchoosegen").window('open');
		}
		
		/* 确认普通收件人并填入到页面 */
		function confirmnewemailgen(){
			var row = $("#newemailgenlist").datagrid('getSelected');
			var name = row.text;
			var id = row.id;
			$("#genwritetext").text(name);
			$("#newemailchoosegen").window('close');
		}
		
		/* 新邮件选取抄送人 */
		function choosecopymen(){
			$("#newemailchoosecopy").window({onOpen:function(){
                $("#newemailchoosecopylist").tree({url: 'get_tree'});
            }});
			$("#newemailchoosecopy").window('open');
		}
		
		/* 确认抄送人并且填入页面 */
		function confirmnewemailcopy(){
			var nodes = $("#newemailchoosecopylist").tree('getChecked');
			var names = new Array();
			for (var i = 0; i < nodes.length; i++) {
				names.push(nodes[i].text);
			}
			$("#copwritetext").text(names);
			$("#newemailchoosecopy").window('close');
		}
		
		/* 现在发送邮件 */
		function writenow(){
			var reservegen=$("#genwritetext").text();
			var copy=$("#copwritetext").text();
			var theme=$("#themetetx").val();
			var text=$("#emailtext").val();
			if(reservegen==""){
				$.messager.alert('提示', '发件人不能为空！', 'info'); 
			}else{
				
				if(copy==""){
					$.post('postemailnocopy',{name:reservegen,copy:copy,theme:theme,text:text},function(data){
						$.messager.alert('提示', '发送成功！', 'info'); 
						$("#genwritetext").text("");
						$("#copwritetext").text("");
						$("#themetetx").val("");
						$("#emailtext").val("");
					});
				}else{
					$.post('postemail',{name:reservegen,copy:copy,theme:theme,text:text},function(data){
						$.messager.alert('提示', '发送成功！', 'info'); 
						$("#genwritetext").text("");
						$("#copwritetext").text("");
						$("#themetetx").val("");
						$("#emailtext").val("");
					});
				}
			}				
		}
		
		/* 只是保存我编辑的邮件 */
		function justsave(){
			var reservegen=$("#genwritetext").text();
			var copy=$("#copwritetext").text();
			var theme=$("#themetetx").val();
			var text=$("#emailtext").val();
			if(reservegen==""){
				$.messager.alert('提示', '发件人不能为空！', 'info'); 
			}else{
				if(copy==""){
					$.post('savepostemailnocopy',{name:reservegen,copy:copy,theme:theme,text:text},function(data){
						$.messager.alert('提示', '暂存成功！', 'info'); 
						$("#genwritetext").text("");
						$("#copwritetext").text("");
						$("#themetetx").val("");
						$("#emailtext").val("");
					});
				}else{
					$.post('savepostemail',{name:reservegen,copy:copy,theme:theme,text:text},function(data){
						$.messager.alert('提示', '暂存成功！', 'info'); 
						$("#genwritetext").text("");
						$("#copwritetext").text("");
						$("#themetetx").val("");
						$("#emailtext").val("");
					});
				}
				
			}				
		}
	</script>
	<div>
		<!-- 写信窗口 -->
		<div id="writeemail" style="float:left;width:89%;height:100%;margin-top:5px;margin-left:5px;
		   ">
			<div id="update" style="margin-left:8px;margin-top:5px;font-size:20px;align:left;">
				${empUseByemailVo.hour }<span style="color:#4E5494;">${empUseByemailVo.emp.empName }。</span>
			</div>
			<div style="margin:5px 10px;height:90%;width:100%;margin-top:10px;">
				<div style="width:97%;height:40px;border:2px solid #DADADA;">
					<span style="float:left;border-bottom:1px solid black;margin-top:10px;margin-left:5px;" onclick="updateinfo()">发件人：《${empUseByemailVo.emp.empName }》						
					</span>
				</div>
				<div style="height:89%;float:left;width:100%;">
					<!-- 普通邮件 -->
					<div id="genenlemail">
						<!-- 操作按钮 -->
						<div style="width:100%;">
							<a onclick="writenow()" class="easyui-linkbutton button-teal handle-btn" style="height:20px;margin-top:8px;margin-bottom:10px;">
								<font>
									发送
								</font>
							</a>
							<a onclick="justsave()" class="easyui-linkbutton button-blue handle-btn" style="height:20px;margin-left:5px;margin-top:8px;margin-bottom:10px;">
								<font>
									存草稿
								</font>
							</a>
						</div>
						<!-- 收件人 -->
						<div>
							<div style="float:left;margin-top:10px;font-size:15px;">
								收件人
							</div>
							<div style="float:left;margin-top:10px;margin-left:10px;width:93%;height:10%;background:white;">
								<a id="genwrite" onclick="choosegenmen()" iconCls="icon-apeople" class="easyui-linkbutton nav_btn" style="float:left;"></a>
								<div id="genwritetext" style="float:left;border:1px solid #DADADA;height:25px;width:96%;margin-top:3px;"></div>
							</div>
						</div>
						<!-- 抄送人 -->
						<div style="clear:both;">
							<div style="float:left;margin-top:10px;font-size:15px;">
								抄送人
							</div>
							<div style="float:left;margin-top:10px;margin-left:10px;width:93%;height:10%;background:white;">
								<a id="copwrite" onclick="choosecopymen()" iconCls="icon-apeople" class="easyui-linkbutton nav_btn" style="float:left;"></a>
								<div id="copwritetext" style="border:1px solid #DADADA;float:left;height:25px;width:96%;margin-top:3px;"></div>
							</div>
						</div>
						<!-- 主题 -->
						<div style="clear:both;">
							<div style="float:left;margin-top:10px;font-size:15px;">
								主&nbsp;&nbsp;&nbsp;题
							</div>
							<div style="font-size:15px;float:left;margin-top:10px;margin-left:12px;width:93%;border:1px solid none;height:10%;background:white;">							
								<input type="text" id="themetetx" style="height:25px;width:99%;border:1px solid #DADADA;">
							</div>
						</div>
						<!-- 内容 -->
						<div style="clear:both;margin-top:50px;clear:both;width:98%;height:300px;font-size:15px;">
							<input id="emailtext" class="easyui-textbox" style="height:100%;width:100%;border:1px solid #DADADA;" 
							label="内&nbsp;&nbsp;&nbsp;容" multiline="true">
						</div>
						
					</div>				
				</div>
			</div>
		</div>
	</div>
	<!-- 更新信息窗口 -->
	<div id="updatewithemail" class="easyui-window" title="更新信息" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save', closed: true" style="width:400px;height:240px;padding:5px;">
        <div class="easyui-layout" data-options="fit:true">
         <div data-options="region:'center'">
         	<form id="modifyemail" method="post" action="modifyemail">
	        	<div style="margin-top:10px;width:180px;float:left;">姓名：${empUseByemailVo.emp.empName }</div>       	
	        	<div style="margin-top:10px;width:180px;float:left;">部门: ${empUseByemailVo.emp.dept.deptName }</div>
	        	<div style="margin-top:10px;width:180px;float:left;">职位：${empUseByemailVo.emp.position.positionName }</div> 
	        	<div style="margin-top:10px;width:180px;float:left;">
	        		<c:if test="${empUseByemailVo.emp.empSex==1 }">
	        			性别：男
	        		</c:if>
	        		<c:if test="${empUseByemailVo.emp.empSex==0 }">
	        			性别：女
	        		</c:if>
	        	</div>
	        	<div style="margin-top:10px;width:180px;float:left;">电话：${empUseByemailVo.emp.empPhone }</div>
	        	<div style="margin-top:10px;width:180px;float:left;">QQ：${empUseByemailVo.emp.emp_QQ }</div>
	        	<div style="margin-top:10px;width:180px;float:left;">生日：${empUseByemailVo.emp.empBirthday }</div>
	        	<div style="margin-top:10px;width:180px;float:left;">入职时间：${empUseByemailVo.emp.empEntertime }</div>
	        	<div style="margin-top:10px;float:left;font-size:20px;">
	        		<span style="font-weight:bolder;">邮箱:</span>
	        		<input name="email" type="text" value="${empUseByemailVo.emp.empEmail }" style="border:1px solid #FF8400; ">
	        	</div>
        	</form>
        </div>
        	<div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;float:left;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true, onClick:function(){
                    $('#modifyemail').form({
                        onSubmit:function(params){
                            return $(this).form('validate');
                        },
                        success:function(info){
                            var b = displayInfo(info);
                            if(b){
                                $.messager.alert('提示', '更新成功！', 'info', function(){
                                	<!-- location='to_index';  -->
                                	$('#updatewithemail').window('close');
                                	$('#update').div('load');
                                });                                
                            }
                        }
                    }).submit();
                }">
                	保存
                </a>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:void(0)" onclick="$('#updatewithemail').window('close');">关闭</a>
            </div>
        
        </div>
    </div>
    
   	<!-- 主收件人选取窗口 -->
    <div id="newemailchoosegen" class="easyui-window" title="选取抄送人" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true, closed: true" style="width:600px;height:500px;padding:5px;">
        <div class="easyui-layout" data-options="fit:true">
            <table border="0" id="newemailgenlist" class="easyui-datagrid" style="height:100%;width:100%;"   
                data-options=" autoRowHeight:false,
				pagination:true,
				singleSelect:true,
				fitColumns:true,
				remoteSort:false
                " >   
                <thead>   
                    <tr style="border:1px solid white;height:100%;width:100%;">
                    	<th data-options="field:'id',checkbox:true"></th> 
                    	<th data-options="field:'text'" align="center"  style="width:50%;">姓名</th>   
                        <th data-options="field:'position'" align="center" style="width:50%;">职位</th>                          
                    </tr>   
                </thead>   
            </table>
                 
            <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
            	<a class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" href="javascript:void(0)" onclick="confirmnewemailgen()">确认</a>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:void(0)" onclick="$('#newemailchoosegen').window('close');">关闭</a>
            </div>
        </div>
    </div>
    
    <!-- 抄送人选取窗口 -->
    <div id="newemailchoosecopy" class="easyui-window" title="选取收件人" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true, closed: true" style="width:600px;height:500px;padding:5px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center'" style="padding:10px;">
                <ul id="newemailchoosecopylist" checkbox="true" lines="true" animate="true" class="easyui-tree"></ul>  
            </div>
            <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" href="javascript:void(0)" onclick="confirmnewemailcopy()">确认</a>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:void(0)" onclick="$('#newemailchoosecopy').window('close');">取消</a>
            </div>
        </div>
    </div>
</body>
</html>